import React, { Component } from "react";
import MainLayout from "@component/mainLayout/mainLayout";
import LivenessCon from "@views/viewCommon/xhfLiveness/index";
import livenessHOC from "@component/livenessHOC/livenessHOC";
import { connect } from "react-redux";
import { Toast } from "antd-mobile";
import xhfTool from "../../../credit/livenessPage/xhfTool";

@connect(state => ({
	authHeader: state.getAppPlatformsDatas.authHeaderStr,
	userName: state.livenessReducer.userName,
	idNo: state.livenessReducer.idNo,
	devicesInfo: state.getAppPlatformsDatas.devicesInfo,
	getAppPlatformsDatas: state.getAppPlatformsDatas
}))
@livenessHOC()
class faceRecognition extends Component {
	constructor(props) {
		super(props);
		this.state = {
			isVisible: false
		};
	}

	componentDidMount() {}
	/**
	 * 小辉付开始人脸
	 */
	async startLive() {
		const {
			authHeaderStr,
			lnid,
			applyNo,
			devicesInfo
		} = this.props.getAppPlatformsDatas;
		let infoStr = sessionStorage.getItem("credit_faceParams_info") || "";
		let { userName, idNo } = infoStr ? JSON.parse(infoStr) : {};
		let post_data = {
			authHeaderStr,
			lnid,
			applyNo,
			devicesInfo,
			userName,
			idNo
		};
		let resp = await xhfTool.startLiveFace(post_data);
		if (resp.status === "1000" && resp.data.code === "0") {
			this.props.history.push("/livenessRet/612");
		} else {
			Toast.info(resp.data.message, 5);
		}
	}
	checkFaceAgreement = e => {
		e.stopPropagation();
		this.props.history.push("/faceAgreement");
	};
	render() {
		const _pageParams = {
			header: {
				title: "人脸识别"
			},
			history: this.props.history,
			cacheLifecycles: this.props.cacheLifecycles
		};
		return (
			<div>
				<MainLayout pageParams={_pageParams}>
					<LivenessCon
						onClick={this.startLive.bind(this)}
						checkFaceAgreement={this.checkFaceAgreement}
					></LivenessCon>
				</MainLayout>
			</div>
		);
	}
}

export default faceRecognition;
